package chen.web.controller.forum;

import org.json.JSONException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import chen.web.region.RegionRepository;


public class RegionController {

	@RequestMapping(value="/region", method=RequestMethod.GET)
	public @ResponseBody JSONResponse province() throws JSONException{
		return JSONResponse.successed(RegionRepository.getAllProvince());
	}
	
	@RequestMapping(value="/region/province/{id}", method=RequestMethod.GET)
	public @ResponseBody JSONResponse city(@PathVariable int id) throws JSONException{
		return JSONResponse.successed(RegionRepository.getCityByProvince(id));
	}
	
	@RequestMapping(value="/region/residence", method=RequestMethod.GET)
	public @ResponseBody JSONResponse  residence() throws JSONException{
		return JSONResponse.successed(RegionRepository.getAllResidence());
	}
}
